package kr.ac.hufs.ice.cap.network;


import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;

import kr.ac.hufs.ice.cap.network.NetworkData;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;

public class NetworkThread_FirstChild extends Thread {
	
	NetworkData nd;
	Handler mHandler;
	int commandState; 
	private final String SERVER_ADDRESS = "http://220.67.124.69/requestinfo/confirm_request.php"; 
	
	public static final int REGISTER = 0;
	
	public NetworkThread_FirstChild(NetworkData nd, Handler mHandler) {
		this.nd = nd;
		this.mHandler = mHandler;
	}
	
	public void setCommand(int command) {
		this.commandState = command;
	}
	
	public void run() {
		Looper.prepare();
		if(commandState == REGISTER) {
			register();	
		}
		
		Looper.loop();
	}
	
	private void register() {
		
		String ParentPhoneNumber = nd.getParentPhoneNumber();
		String FirstChildName = nd.getFirstChildName();
		String FirstChildGrade = nd.getFirstChildGrade();
		String FirstChildClass = nd.getFirstChildClass();
		String FirstChildSchool = nd.getFirstChildSchool();

		PageStreamer ps = new PageStreamer();
		ps.setRootURL(SERVER_ADDRESS);

		ps.add("ParentPhoneNumber", ParentPhoneNumber);
		ps.add("FirstChildSchool", FirstChildSchool);
		ps.add("FirstChildGrade", FirstChildGrade);
		ps.add("FirstChildClass", FirstChildClass);
		ps.add("FirstChildName", FirstChildName);
		
		String returnMsg = ps.getPageStream();
		Message msg = new Message();
		if(returnMsg.contains("1")) {
			msg.obj = returnMsg;
		}
		mHandler.sendMessage(msg);
	}
}
